package com.ptszyxx.popose.module.main.mine.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.mine.MineLookResult;
import com.ysg.utils.YStringUtil;

import java.util.HashMap;
import java.util.Map;

public class MineLookTabVM extends BaseViewModel<CommonRepository> {

    public MineLookTabVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onVipEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onVipCommand = new BindingCommand(() ->
        YActivityUtil.getInstance().jumpMineVip(this)
    );
    //=========================================接口：start===========================================

    /**
     */
    public void requestLookList(boolean refresh, int tab){
        if (refresh){
            page = 1;
        } else {
            page++;
        }
        Map<String, String> map = new HashMap<>();
        map.put("type", String.valueOf(tab));
        map.put("pageno", String.valueOf(page));
        HttpUtils.getInstance()
                .data(model.lookList(map), this,
                        new OnSuccessResult<MineLookResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<MineLookResult> response) {
                                if (YStringUtil.eq(1, response.getData().getIsvip()) || YStringUtil.eq(2, tab)){
                                    uc.onRefreshEvent.setValue(response.getData().getList());
                                }else{
                                    uc.onVipEvent.setValue(response.getData().getList());
                                }
                            }
                        });
    }



}
